package com.zhudi.utils;


import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.crypto.digest.HMac;
import cn.hutool.crypto.digest.HmacAlgorithm;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class SignatureUtils {

    /**
     * 获取参数的签名
     * @param message 参数集合，参数们会被合并成一个字符串，以 . 区分开每个子串
     * @return 签名
     */
   public static String signByHmacSHA256(String ...message){
       String join = String.join(".",message);

// 此处密钥如果有非ASCII字符，考虑编码
       byte[] key = join.getBytes();
       HMac mac = new HMac(HmacAlgorithm.HmacSHA256, key);

// b977f4b13f93f549e06140971bded384
       String HmacSHA256 = mac.digestHex(join);
       return HmacSHA256;
   }
    /**
     * 生成一个新的ak、sk
     * @return k为ak，v为sk
     */
    public static Map<String,String> getAccessKeyAndSecertKey(){
        SecureRandom random = new SecureRandom();

        String accessKey = new UUID(random.nextLong(), random.nextLong()).toString().replace("-", "");
        String secertKey = new UUID(random.nextLong(), random.nextLong()).toString().replace("-", "");
        Map<String,String> result = new HashMap<>();
        result.put(accessKey,secertKey);
        return result;
    }


    
}

